package com.gedeon.controller;


import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;







import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.ericsson.middleware.dao.LampDao;
import com.ericsson.middleware.entities.LampState;

public class HelloWorldController extends AbstractController{

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		LampDao dao = new LampDao();

		List<LampState> lista = dao.findAll();
		LampState state = dao.findById("AguasSaoPedro_Rua1_05");
		ModelAndView model = new ModelAndView("HelloWorldPage");
		model.addObject("msg", "hello world");

		Map<String,Integer> creditCardTypes = new LinkedHashMap<String,Integer>();
		for (LampState temp: lista) {
			creditCardTypes.put(temp.getId(), temp.getSerialID());
		}

		model.addObject("teste", creditCardTypes);

		return model;
	}

	@ModelAttribute("creditCardTypes")
	public Map<String,String> populateCreditCardTypes() {
		Map<String,String> creditCardTypes = new LinkedHashMap<String,String>();
		creditCardTypes.put("VS", "Visa");creditCardTypes.put("MC", "MasterCard");
		creditCardTypes.put("AE", "American Express");
		creditCardTypes.put("DS", "Discover");creditCardTypes.put("DC", "Diner's Club");                
		return creditCardTypes;
	}
}